package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "用户端-订单接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 订单提交
     * @param ordersDTO
     * @return
     */
    @ApiOperation("用户下单")
    @PostMapping("/add")
    public  Result<OrderSubmitVO> add(@RequestBody  OrdersDTO ordersDTO) {
        log.info("订单提交");
        OrderSubmitVO result = orderService.add(ordersDTO);
        return Result.success(result);
    }

    /**
     * 订单支付
     * @param orderId
     * @return
     */
    @PostMapping("/pay")
    @ApiOperation("订单支付")
    public Result pay(String orderId) {
        log.info("订单支付");
        orderService.pay(orderId);
        return Result.success();
    }

    /**
     * 订单催单
     * @param orderId
     * @return
     */
    @GetMapping("/reminder")
    @ApiOperation("订单催单")
    public Result reminder(Long orderId) {
        log.info("订单催单");
        orderService.reminder(orderId);
        return Result.success();
    }
    /**
     * 获取订单记录列表
     */
    @GetMapping("/list")
    @ApiOperation("获取订单记录列表")
    public Result<PageResult> getOrderList(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("获取订单记录列表");
        System.out.println(ordersPageQueryDTO);
        PageResult result = orderService.getOrderList(ordersPageQueryDTO);
        return Result.success(result);
    }

    /**
     * 获取订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation("获取订单详情")
    public Result<OrderVO> getOrderDetail(Long orderId) {
        log.info("获取订单详情");
        OrderVO result = orderService.getOrderDetail(orderId);
        return Result.success(result);
    }

}
